package com.practice.Optional语法糖;
import java.util.Optional;
/**
 * Created by IntelliJ IDEA2021.3
 * @Author: Tenghw
 * @Date: 2023/02/24  15:53
 * @Description: 过滤
 */
public class Demo3 {
    public static void main(String[] args) {
        Student student = new Student("李四", 3);
        Optional<Student> os1 = Optional.ofNullable(student);
        Optional<Student> optional = os1.filter(p -> p.getName().equals("李四"));
        System.out.println(optional);
        os1.filter(p -> p.getName().equals("李四")).ifPresent(x -> System.out.println(x.getAge()));
    }
}
